package cn.bigcontainer.alt.common.exception;

import org.springframework.util.StringUtils;

public class BigResultCode {

	private String msg = "未知错误!";

	private Integer code = 0;

	private Object[] args;

	public BigResultCode() {
	}

	public BigResultCode(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public Integer getCode() {
		return code;
	}

	public Boolean getSuccess () {
		return code == 1;
	}
	
	public BigResultCode setMsgArgs(Object... args) {
		if (args == null || args.length == 0) {
			this.args = new Object[0];
			return this;
		}
		// msg = String.format(msg, args);
		this.args = args;
		return this;
	}

	public String getMsg() {
		return String.format(msg, args);
	}
	
	public String getMessage () {
		return getMsg();
	}

	public BigResultCode setMsg(String msg) {
		if (!StringUtils.isEmpty(msg)) {
			this.msg = msg;
		}
		return this;
	}

	private Object content = "";

	public Object getContent() {
		return content;
	}

	public BigResultCode setContent(Object content) {
		if (content != null) {
			this.content = content;
		}
		return this;
	}

	/**
	 * @return
	 */
	public BigResultCode cloneCode() {
		BigResultCode code = new BigResultCode(this.code, this.msg);
		code.setMsgArgs(args);
		code.setContent(this.content);
		return code;
	}

	/**
	 * @return
	 */
	public static BigResultCode getSuccessCode () {
		return new BigResultCode(1, "操作成功！");
	}

	/**
	 * @return
	 */
	public static BigResultCode getUnknownCode() {
		return new BigResultCode();
	}
}
